package edu.pw.treegrid.client.report.view;

import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.events.CloseClientEvent;
import com.smartgwt.client.widgets.form.FilterBuilder;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;

import edu.pw.treegrid.client.report.controller.ReportController;

public class SettingsWindow extends Window {
	private ReportController controller;
	public ToolStripButton okButton;
	public ToolStripButton cancelButton;

	
	public SettingsWindow(
			ReportController controller
			, HierarchyPanel hierarchyPanel
			, FilterBuilder filterBuilder
		)
	{	
		this.controller = controller;
		this.setWidth100();  
		this.setHeight100();   
		this.setTitle("Ustawienia");   
		this.setShowMinimizeButton(false);   
		this.setIsModal(true);   
		this.setShowModalMask(true);   
		this.centerInPage();
		this.setKeepInParentRect(true);
		this.setMembersMargin(5);
		
		this.addCloseClickHandler(new CloseClickHandler() {   
            public void onCloseClick(CloseClientEvent event) {   
            	SettingsWindow.this.controller.onSettingsCancel();
            }   
        });
		
		final TabSet topTabSet = new TabSet();      
        topTabSet.setWidth100();   
        topTabSet.setHeight100();   
  
        Tab filterTab = new Tab("Filtr", "silk/filter.png");
        filterTab.setPane(filterBuilder);   
  
        Tab hierachyTab = new Tab("Hierarchia", "silk/chart_organisation.png");   
        hierachyTab.setPane(hierarchyPanel);   
  
        topTabSet.addTab(hierachyTab);
        topTabSet.addTab(filterTab);
        
        this.addItem(topTabSet); 
        
        ToolStrip buttonsToolbar = new ToolStrip();
        okButton = new ToolStripButton("OK");   
        okButton.addClickHandler(new ClickHandler() {   
			public void onClick(ClickEvent event) {
            	SettingsWindow.this.controller.onSettingsOK();
            }   
        });
        okButton.setDisabled(true);
        
        cancelButton = new ToolStripButton("Cancel");
        cancelButton.addClickHandler(new ClickHandler() {   
            public void onClick(ClickEvent event) {   
            	SettingsWindow.this.controller.onSettingsCancel();
            }   
        });
        cancelButton.setDisabled(true);
        
        buttonsToolbar.addMember(okButton);
        buttonsToolbar.addMember(cancelButton);
        buttonsToolbar.setWidth100();
        this.addItem(buttonsToolbar);
	}
}
